package github.kawaiior.yuanchuxiuzhen.common.entity.addon.model;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import github.kawaiior.yuanchuxiuzhen.common.entity.addon.EagleOwlEntity;
import github.kawaiior.yuanchuxiuzhen.util.RenderUtil;
import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.client.renderer.model.ModelRenderer;

public class EagleOwlEntityModel extends EntityModel<EagleOwlEntity> {

    private final ModelRenderer body;
    private final ModelRenderer rightarm;
    private final ModelRenderer rightarm2;
    private final ModelRenderer leftarm;
    private final ModelRenderer leftarm2;
    private final ModelRenderer head;

    public EagleOwlEntityModel(){
        this.textureWidth = 76;
        this.textureHeight = 58;
        this.body = new ModelRenderer(this);
        this.body.setRotationPoint(0.0F, 16.0F, 0.0F);
        RenderUtil.setRotationAngle(this.body, -0.5236F, 0.0F, 0.0F);

        addBox(this.body, 0, 16, -3.0F, -3.0F, -6.0F, 6, 6, 12, 0.0F, false);
        addBox(this.body, 8, 0, -6.0F, -2.0F, 6.0F, 12, 0, 12, 0.0F, false);
        addBox(this.body, 0, 22, -2.0F, -3.0F, -8.0F, 4, 4, 2, 0.0F, false);
        addBox(this.body, 0, 16, -1.5F, -3.5F, -11.0F, 3, 3, 3, 0.0F, false);
        addBox(this.body, 0, 12, -1.0F, -4.0F, -13.0F, 2, 2, 2, 0.0F, false);
        addBox(this.body, 45, 0, -5.0F, 0.0F, 0.0F, 3, 6, 4, 0.0F, false);
        addBox(this.body, 24, 20, -5.5F, 6.1F, -2.0F, 4, 4, 4, 0.0F, false);
        addBox(this.body, 44, 0, 2.0F, 0.0F, 0.0F, 3, 6, 4, 0.0F, false);
        addBox(this.body, 24, 20, 1.5F, 6.1F, -2.0F, 4, 4, 4, 0.0F, false);

        this.rightarm = new ModelRenderer(this);
        this.rightarm.setRotationPoint(-3.0F, 13.0F, 0.0F);
        RenderUtil.setRotationAngle(this.rightarm, -0.5236F, 0.0F, 0.3491F);
        addBox(this.rightarm, 0, 34, -19.0F, 0.0F, -9.0F, 20, 0, 12, 0.0F, false);

        this.rightarm2 = new ModelRenderer(this);
        this.rightarm2.setRotationPoint(-19.0F, 0.0F, -3.0F);
        RenderUtil.setRotationAngle(this.rightarm2, 0.0F, 0.0F, -0.3491F);
        this.rightarm.addChild(this.rightarm2);
        addBox(this.rightarm2, 40, 19, -10.0F, 0.0F, -4.0F, 10, 0, 8, 0.0F, false);

        this.leftarm = new ModelRenderer(this);
        this.leftarm.setRotationPoint(3.0F, 13.0F, 0.0F);
        RenderUtil.setRotationAngle(this.leftarm, -0.5236F, 0.0F, -0.3491F);
        addBox(this.leftarm, 0, 46, -1.0F, 0.0F, -9.0F, 20, 0, 12, 0.0F, false);

        this.leftarm2 = new ModelRenderer(this);
        this.leftarm2.setRotationPoint(19.0F, 0.0F, -3.0F);
        RenderUtil.setRotationAngle(this.leftarm2, 0.0F, 0.0F, 0.3491F);
        this.leftarm.addChild(this.leftarm2);
        addBox(this.leftarm2, 40, 10, 0.0F, 0.0F, -4.0F, 10, 0, 8, 0.0F, false);

        this.head = new ModelRenderer(this);
        this.head.setRotationPoint(0.0F, 7.0F, -10.0F);
        addBox(this.head, 0, 0, -2.0F, -3.0F, -4.0F, 4, 4, 4, 0.0F, false);
        addBox(this.head, 0, 8, -1.0F, -1.0F, -6.0F, 2, 2, 2, 0.0F, false);
        addBox(this.head, 12, 0, -1.0F, 0.0F, -7.0F, 2, 2, 1, 0.0F, false);
    }

    private void addBox(ModelRenderer mb, int tx, int ty, float x, float y, float z, float width, float height, float depth, float delta, boolean mirrorIn){
        ModelRenderer mr = new ModelRenderer(this);
        mb.addChild(mr);
        mr.setTextureOffset(tx, ty).addBox(x,y,z,width,height,depth,delta,mirrorIn);
    }

    @Override
    public void setRotationAngles(EagleOwlEntity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
        this.head.rotateAngleY = netHeadYaw / 57.295776F;
        this.head.rotateAngleX = headPitch / 57.295776F;
    }

    @Override
    public void render(MatrixStack matrixStackIn, IVertexBuilder bufferIn, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) {
        this.body.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.rightarm.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.leftarm.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.head.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
    }
}
